/**
 * This is a generated class and is not intended for modification.  To customize behavior
 * of this value object you may modify the generated sub-class of this class - VoCurrency.as.
 */

package com.model.valueObjects
{
import com.adobe.fiber.services.IFiberManagingService;
import com.adobe.fiber.util.FiberUtils;
import com.adobe.fiber.valueobjects.IValueObject;
import flash.events.Event;
import flash.events.EventDispatcher;
import mx.binding.utils.ChangeWatcher;
import mx.events.PropertyChangeEvent;
import mx.validators.ValidationResult;

import flash.net.registerClassAlias;
import flash.net.getClassByAlias;
import com.adobe.fiber.core.model_internal;
import com.adobe.fiber.valueobjects.IPropertyIterator;
import com.adobe.fiber.valueobjects.AvailablePropertyIterator;

use namespace model_internal;

[ExcludeClass]
public class _Super_VoCurrency extends flash.events.EventDispatcher implements com.adobe.fiber.valueobjects.IValueObject
{
    model_internal static function initRemoteClassAliasSingle(cz:Class) : void
    {
        try
        {
            if (flash.net.getClassByAlias("VoCurrency") == null)
            {
                flash.net.registerClassAlias("VoCurrency", cz);
            }
        }
        catch (e:Error)
        {
            flash.net.registerClassAlias("VoCurrency", cz);
        }
    }

    model_internal static function initRemoteClassAliasAllRelated() : void
    {
    }

    model_internal var _dminternal_model : _VoCurrencyEntityMetadata;

    /**
     * properties
     */
    private var _internal_cre_datetime : String;
    private var _internal_currency_value : Number = Number(0);
    private var _internal_currency_name : String;
    private var _internal_currency_country : String;
    private var _internal_activestatus : Boolean;
    private var _internal_currency_symbol : String;
    private var _internal_serialnumber : int;
    private var _internal_currency_code : Number = Number(0);
    private var _internal_cre_userid : int;

    private static var emptyArray:Array = new Array();

    // Change this value according to your application's floating-point precision
    private static var epsilon:Number = 0.0001;

    /**
     * derived property cache initialization
     */
    model_internal var _cacheInitialized_isValid:Boolean = false;

    model_internal var _changeWatcherArray:Array = new Array();

    public function _Super_VoCurrency()
    {
        _model = new _VoCurrencyEntityMetadata(this);

        // Bind to own data properties for cache invalidation triggering
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "cre_datetime", model_internal::setterListenerCre_datetime));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "currency_name", model_internal::setterListenerCurrency_name));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "currency_country", model_internal::setterListenerCurrency_country));
        model_internal::_changeWatcherArray.push(mx.binding.utils.ChangeWatcher.watch(this, "currency_symbol", model_internal::setterListenerCurrency_symbol));

    }

    /**
     * data property getters
     */

    [Bindable(event="propertyChange")]
    public function get cre_datetime() : String
    {
        return _internal_cre_datetime;
    }

    [Bindable(event="propertyChange")]
    public function get currency_value() : Number
    {
        return _internal_currency_value;
    }

    [Bindable(event="propertyChange")]
    public function get currency_name() : String
    {
        return _internal_currency_name;
    }

    [Bindable(event="propertyChange")]
    public function get currency_country() : String
    {
        return _internal_currency_country;
    }

    [Bindable(event="propertyChange")]
    public function get activestatus() : Boolean
    {
        return _internal_activestatus;
    }

    [Bindable(event="propertyChange")]
    public function get currency_symbol() : String
    {
        return _internal_currency_symbol;
    }

    [Bindable(event="propertyChange")]
    public function get serialnumber() : int
    {
        return _internal_serialnumber;
    }

    [Bindable(event="propertyChange")]
    public function get currency_code() : Number
    {
        return _internal_currency_code;
    }

    [Bindable(event="propertyChange")]
    public function get cre_userid() : int
    {
        return _internal_cre_userid;
    }

    /**
     * data property setters
     */

    public function set cre_datetime(value:String) : void
    {
        var oldValue:String = _internal_cre_datetime;
        if (oldValue !== value)
        {
            _internal_cre_datetime = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "cre_datetime", oldValue, _internal_cre_datetime));
        }
    }

    public function set currency_value(value:Number) : void
    {
        var oldValue:Number = _internal_currency_value;
        if (isNaN(_internal_currency_value) == true || Math.abs(oldValue - value) > epsilon)
        {
            _internal_currency_value = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "currency_value", oldValue, _internal_currency_value));
        }
    }

    public function set currency_name(value:String) : void
    {
        var oldValue:String = _internal_currency_name;
        if (oldValue !== value)
        {
            _internal_currency_name = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "currency_name", oldValue, _internal_currency_name));
        }
    }

    public function set currency_country(value:String) : void
    {
        var oldValue:String = _internal_currency_country;
        if (oldValue !== value)
        {
            _internal_currency_country = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "currency_country", oldValue, _internal_currency_country));
        }
    }

    public function set activestatus(value:Boolean) : void
    {
        var oldValue:Boolean = _internal_activestatus;
        if (oldValue !== value)
        {
            _internal_activestatus = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "activestatus", oldValue, _internal_activestatus));
        }
    }

    public function set currency_symbol(value:String) : void
    {
        var oldValue:String = _internal_currency_symbol;
        if (oldValue !== value)
        {
            _internal_currency_symbol = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "currency_symbol", oldValue, _internal_currency_symbol));
        }
    }

    public function set serialnumber(value:int) : void
    {
        var oldValue:int = _internal_serialnumber;
        if (oldValue !== value)
        {
            _internal_serialnumber = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "serialnumber", oldValue, _internal_serialnumber));
        }
    }

    public function set currency_code(value:Number) : void
    {
        var oldValue:Number = _internal_currency_code;
        if (isNaN(_internal_currency_code) == true || Math.abs(oldValue - value) > epsilon)
        {
            _internal_currency_code = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "currency_code", oldValue, _internal_currency_code));
        }
    }

    public function set cre_userid(value:int) : void
    {
        var oldValue:int = _internal_cre_userid;
        if (oldValue !== value)
        {
            _internal_cre_userid = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "cre_userid", oldValue, _internal_cre_userid));
        }
    }

    /**
     * Data property setter listeners
     *
     * Each data property whose value affects other properties or the validity of the entity
     * needs to invalidate all previously calculated artifacts. These include:
     *  - any derived properties or constraints that reference the given data property.
     *  - any availability guards (variant expressions) that reference the given data property.
     *  - any style validations, message tokens or guards that reference the given data property.
     *  - the validity of the property (and the containing entity) if the given data property has a length restriction.
     *  - the validity of the property (and the containing entity) if the given data property is required.
     */

    model_internal function setterListenerCre_datetime(value:flash.events.Event):void
    {
        _model.invalidateDependentOnCre_datetime();
    }

    model_internal function setterListenerCurrency_name(value:flash.events.Event):void
    {
        _model.invalidateDependentOnCurrency_name();
    }

    model_internal function setterListenerCurrency_country(value:flash.events.Event):void
    {
        _model.invalidateDependentOnCurrency_country();
    }

    model_internal function setterListenerCurrency_symbol(value:flash.events.Event):void
    {
        _model.invalidateDependentOnCurrency_symbol();
    }


    /**
     * valid related derived properties
     */
    model_internal var _isValid : Boolean;
    model_internal var _invalidConstraints:Array = new Array();
    model_internal var _validationFailureMessages:Array = new Array();

    /**
     * derived property calculators
     */

    /**
     * isValid calculator
     */
    model_internal function calculateIsValid():Boolean
    {
        var violatedConsts:Array = new Array();
        var validationFailureMessages:Array = new Array();

        var propertyValidity:Boolean = true;
        if (!_model.cre_datetimeIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_cre_datetimeValidationFailureMessages);
        }
        if (!_model.currency_nameIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_currency_nameValidationFailureMessages);
        }
        if (!_model.currency_countryIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_currency_countryValidationFailureMessages);
        }
        if (!_model.currency_symbolIsValid)
        {
            propertyValidity = false;
            com.adobe.fiber.util.FiberUtils.arrayAdd(validationFailureMessages, _model.model_internal::_currency_symbolValidationFailureMessages);
        }

        model_internal::_cacheInitialized_isValid = true;
        model_internal::invalidConstraints_der = violatedConsts;
        model_internal::validationFailureMessages_der = validationFailureMessages;
        return violatedConsts.length == 0 && propertyValidity;
    }

    /**
     * derived property setters
     */

    model_internal function set isValid_der(value:Boolean) : void
    {
        var oldValue:Boolean = model_internal::_isValid;
        if (oldValue !== value)
        {
            model_internal::_isValid = value;
            _model.model_internal::fireChangeEvent("isValid", oldValue, model_internal::_isValid);
        }
    }

    /**
     * derived property getters
     */

    [Transient]
    [Bindable(event="propertyChange")]
    public function get _model() : _VoCurrencyEntityMetadata
    {
        return model_internal::_dminternal_model;
    }

    public function set _model(value : _VoCurrencyEntityMetadata) : void
    {
        var oldValue : _VoCurrencyEntityMetadata = model_internal::_dminternal_model;
        if (oldValue !== value)
        {
            model_internal::_dminternal_model = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, "_model", oldValue, model_internal::_dminternal_model));
        }
    }

    /**
     * methods
     */


    /**
     *  services
     */
    private var _managingService:com.adobe.fiber.services.IFiberManagingService;

    public function set managingService(managingService:com.adobe.fiber.services.IFiberManagingService):void
    {
        _managingService = managingService;
    }

    model_internal function set invalidConstraints_der(value:Array) : void
    {
        var oldValue:Array = model_internal::_invalidConstraints;
        // avoid firing the event when old and new value are different empty arrays
        if (oldValue !== value && (oldValue.length > 0 || value.length > 0))
        {
            model_internal::_invalidConstraints = value;
            _model.model_internal::fireChangeEvent("invalidConstraints", oldValue, model_internal::_invalidConstraints);
        }
    }

    model_internal function set validationFailureMessages_der(value:Array) : void
    {
        var oldValue:Array = model_internal::_validationFailureMessages;
        // avoid firing the event when old and new value are different empty arrays
        if (oldValue !== value && (oldValue.length > 0 || value.length > 0))
        {
            model_internal::_validationFailureMessages = value;
            _model.model_internal::fireChangeEvent("validationFailureMessages", oldValue, model_internal::_validationFailureMessages);
        }
    }

    model_internal var _doValidationCacheOfCre_datetime : Array = null;
    model_internal var _doValidationLastValOfCre_datetime : String;

    model_internal function _doValidationForCre_datetime(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfCre_datetime != null && model_internal::_doValidationLastValOfCre_datetime == value)
           return model_internal::_doValidationCacheOfCre_datetime ;

        _model.model_internal::_cre_datetimeIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isCre_datetimeAvailable && _internal_cre_datetime == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "cre_datetime is required"));
        }

        model_internal::_doValidationCacheOfCre_datetime = validationFailures;
        model_internal::_doValidationLastValOfCre_datetime = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfCurrency_name : Array = null;
    model_internal var _doValidationLastValOfCurrency_name : String;

    model_internal function _doValidationForCurrency_name(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfCurrency_name != null && model_internal::_doValidationLastValOfCurrency_name == value)
           return model_internal::_doValidationCacheOfCurrency_name ;

        _model.model_internal::_currency_nameIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isCurrency_nameAvailable && _internal_currency_name == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "currency_name is required"));
        }

        model_internal::_doValidationCacheOfCurrency_name = validationFailures;
        model_internal::_doValidationLastValOfCurrency_name = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfCurrency_country : Array = null;
    model_internal var _doValidationLastValOfCurrency_country : String;

    model_internal function _doValidationForCurrency_country(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfCurrency_country != null && model_internal::_doValidationLastValOfCurrency_country == value)
           return model_internal::_doValidationCacheOfCurrency_country ;

        _model.model_internal::_currency_countryIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isCurrency_countryAvailable && _internal_currency_country == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "currency_country is required"));
        }

        model_internal::_doValidationCacheOfCurrency_country = validationFailures;
        model_internal::_doValidationLastValOfCurrency_country = value;

        return validationFailures;
    }
    
    model_internal var _doValidationCacheOfCurrency_symbol : Array = null;
    model_internal var _doValidationLastValOfCurrency_symbol : String;

    model_internal function _doValidationForCurrency_symbol(valueIn:Object):Array
    {
        var value : String = valueIn as String;

        if (model_internal::_doValidationCacheOfCurrency_symbol != null && model_internal::_doValidationLastValOfCurrency_symbol == value)
           return model_internal::_doValidationCacheOfCurrency_symbol ;

        _model.model_internal::_currency_symbolIsValidCacheInitialized = true;
        var validationFailures:Array = new Array();
        var errorMessage:String;
        var failure:Boolean;

        var valRes:ValidationResult;
        if (_model.isCurrency_symbolAvailable && _internal_currency_symbol == null)
        {
            validationFailures.push(new ValidationResult(true, "", "", "currency_symbol is required"));
        }

        model_internal::_doValidationCacheOfCurrency_symbol = validationFailures;
        model_internal::_doValidationLastValOfCurrency_symbol = value;

        return validationFailures;
    }
    

}

}
